<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Vue 简易计算器</title>
</head>
<body>
  <div id="app">
    <!-- 第一个数 -->
    <input type="text" v-model="n1">
    <!-- 运算符号 -->
    <select v-model="opt">
      <option value="+">+</option>
      <option value="-">-</option>
      <option value="*">*</option>
      <option value="/">/</option>
    </select>
    <!-- 第二个数 -->
    <input type="text" v-model="n2">
    <!-- 等号 进行计算 -->
    <button @click="calc">=</button>
    <!-- 结果显示 -->
    <input type="text" v-model="result">

  </div>
</body>
<script src="./src/vue.js"></script>
<script>
  const vm = new Vue({
    el: '#app',
    data: {
      n1: 0,
      n2: 0,
      result: 0,
      opt: '+'
    },
    methods: {
      calc(){
        // 计算结果 n1 +-*/ n2 = result
        switch (this.opt) {
          case '+':
            this.result = parseInt(this.n1) + parseInt(this.n2);
            break;
          case '-':
            this.result = parseInt(this.n1) - parseInt(this.n2);
            break;
          case '*':
            this.result = parseInt(this.n1) * parseInt(this.n2);
            break;
          case '/':
            this.result = parseInt(this.n1) / parseInt(this.n2);
            break;
          default:
            break;
        }

      }
    },
  })
</script>
</html>